package com.practice.springboot_01_zwj.entity;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

@AllArgsConstructor
@NoArgsConstructor
@Data
public class SubTask {
    private Integer subId; //子任务Id
    private String subName;  //子任务名
    private String subDescription; //任务详细描述
    private String subExecutor; //子任务执行人
    private String subBelonging; //子任务执行人归属组织
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date planStartTime; //计划开始时间
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date planFinishTime;  //计划结束时间
    private Double finishProgress;  //子任务完成进度(0-100)
    private Integer mainId; //主任务id（外键）
    @JsonBackReference
    private MainTask mainTask;
    private List<String> subExecutors;       // 多个执行人（逗号分隔）
    private List<String> subBelongings;      // 多个归属组织（逗号分隔）
    private String subExecutorAcNames; // 新增字段：执行人中文名称列表（逗号分隔）

    private Double avgRating; // 批量子任务自评分平均值

    public Double getAvgRating() {
        return avgRating;
    }

    public void setAvgRating(Double avgRating) {
        this.avgRating = avgRating;
    }

    public String getSubExecutorAcNames() {
        return subExecutorAcNames;
    }

    public void setSubExecutorAcNames(String subExecutorAcNames) {
        this.subExecutorAcNames = subExecutorAcNames;
    }

    // Getter 和 Setter 方法
    public List<String> getSubExecutors() {
        if (subExecutor != null && !subExecutor.isEmpty()) {
            return Arrays.asList(subExecutor.split(","));
        }
        return new ArrayList<>();
    }

    public void setSubExecutors(List<String> subExecutors) {
        this.subExecutors = subExecutors;
        if (subExecutors != null && !subExecutors.isEmpty()) {
            this.subExecutor = String.join(",", subExecutors);
        } else {
            this.subExecutor = null;
        }
    }

    public List<String> getSubBelongings() {
        if (subBelonging != null && !subBelonging.isEmpty()) {
            return Arrays.asList(subBelonging.split(","));
        }
        return new ArrayList<>();
    }

    public void setSubBelongings(List<String> subBelongings) {
        this.subBelongings = subBelongings;
        if (subBelongings != null && !subBelongings.isEmpty()) {
            this.subBelonging = String.join(",", subBelongings);
        } else {
            this.subBelonging = null;
        }
    }

    public MainTask getMainTask() {
        return mainTask;
    }

    public void setMainTask(MainTask mainTask) {
        this.mainTask = mainTask;
    }

    public Integer getSubId() {
        return subId;
    }

    public void setSubId(Integer subId) {
        this.subId = subId;
    }

    public String getSubName() {
        return subName;
    }

    public void setSubName(String subName) {
        this.subName = subName;
    }

    public String getSubDescription() {
        return subDescription;
    }

    public void setSubDescription(String subDescription) {
        this.subDescription = subDescription;
    }

    public String getSubExecutor() {
        return subExecutor;
    }

    public void setSubExecutor(String subExecutor) {
        this.subExecutor = subExecutor;
    }

    public String getSubBelonging() {
        return subBelonging;
    }

    public void setSubBelonging(String subBelonging) {
        this.subBelonging = subBelonging;
    }

    public Date getPlanStartTime() {
        return planStartTime;
    }

    public void setPlanStartTime(Date planStartTime) {
        this.planStartTime = planStartTime;
    }

    public Date getPlanFinishTime() {
        return planFinishTime;
    }

    public void setPlanFinishTime(Date planFinishTime) {
        this.planFinishTime = planFinishTime;
    }

    public Double getFinishProgress() {
        return finishProgress;
    }

    public void setFinishProgress(Double finishProgress) {
        this.finishProgress = finishProgress;
    }

    public Integer getMainId() {
        return mainId;
    }

    public void setMainId(Integer mainId) {
        this.mainId = mainId;
    }
}
